<template>
  <div id="info-table">
    <table>
      <tr>
        <td><img :src="user.avatar" alt=""/></td>
      </tr>
      <tr>
        <td><h2>{{user.username}}</h2></td>
      </tr>
      <tr>
        <td><p @click="updateInfo">修改资料</p></td>
      </tr>
      <tr>
        <td>
          <p @click="updatePassword">修改密码</p>
        </td>
      </tr>
    </table>
  </div>
</template>

<script>
import {getUserDetail} from "@/network/userRequest";

export default {
  name: "InfoTable",
  data() {
    return {
      user: {}
    }
  },
  methods: {
    //网络请求
    getUserDetail() {
      getUserDetail().then(res => {
        this.user = res.data;
        this.user.avatar = "data:image/jpg;base64," + res.data.avatar;
      })
    },

    //事件监听
    updateInfo() {
      this.$emit("updateInfo");
    },
    updatePassword() {
      this.$emit("updatePassword");
    }
  },
  created() {
    this.getUserDetail();
  }
}
</script>

<style scoped>
  #info-table table{
    display: inline-block;
    text-align: center;
    padding: 20px;
    background-color: rgba(255, 255, 255, 0.9);
    border: 1px solid #d5d5d5;
    box-shadow: 5px 5px 5px rgba(0, 0, 0, 0.3);
  }

  #info-table img {
    width: 300px;
    padding: 3px;
    border: 1px solid #eeeeee;
  }

  #info-table p {
    height: 1.5em;
    width: 50%;
    margin: 5px auto;
    font-size: 14px;
    color: white;
    background-color: #22a1d6;
    border-radius: 5px;
  }

  #info-table p:hover {
    background-color: #00b5e5;
    cursor: pointer;
  }

</style>